﻿using DistributedVisionRunner.Module.Views;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using System.Windows.Markup;

namespace DistributedVisionRunner.Module.Converters
{
    public class PlacementOptionSelectionConverter : MarkupExtension, IValueConverter
    {

        public static List<PlacementOptionItem> OptionItems { get; } = new List<PlacementOptionItem>()
        {
            new PlacementOptionItem()
            {
                DisplayText = "垂直堆叠", PlacementMethod = ItemPlacementMethod.VerticalStack
            },
            new PlacementOptionItem()
            {
                DisplayText = "水平堆叠", PlacementMethod = ItemPlacementMethod.HorizontalStack
            },
            new PlacementOptionItem()
            {
                DisplayText = "自动换行", PlacementMethod = ItemPlacementMethod.Wrap
            },
            new PlacementOptionItem()
            {
                DisplayText = "固定列数", PlacementMethod = ItemPlacementMethod.UniformGrid
            },
        };


        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return this;
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var placement = (ItemPlacementMethod)value;
            return OptionItems.First(p => p.PlacementMethod == placement);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var item = (PlacementOptionItem)value;
            return item.PlacementMethod;
        }
    }
}